<template>
    <div class="content-container">
        <a-modal
            :title="modalTitle"
            v-model="modalShow"
            @ok="onSubmit"
            :width="1000"
            okText="确认"
            cancelText="取消"
            :maskClosable="false"
        >
            <a-form :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
                <a-row>
                    <a-col span="12">
                        <a-form-item label="项目编码">
                            <a-col span="20">
                                <a-input disabled v-model="form.code" />
                            </a-col>
                            <a-col span="4">
                                <a-button
                                    type="primary"
                                    block
                                    icon="search"
                                    @click="onSearch('project')"
                                />
                            </a-col>
                        </a-form-item>
                    </a-col>
                    <a-col span="12">
                        <a-form-item label="项目名称">
                            <a-input disabled v-model="form.name" />
                        </a-form-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-item label="单位">
                            <a-input disabled v-model="form.measureUnit" />
                        </a-form-item>
                    </a-col>
                    <a-col span="12">
                        <a-form-item label="标准值">
                            <a-input v-model="form.standardValue" />
                        </a-form-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-item label="上下限" style="width:100%">
                            <a-input
                                style=" width: 100px; text-align: center"
                                placeholder="最小值"
                                v-model="form.minimumValue"
                            />
                            <a-input
                                style=" width: 30px; border-left: 0; pointer-events: none; backgroundColor: #fff"
                                placeholder="~"
                                disabled
                            />
                            <a-input
                                style="width: 100px; text-align: center; border-left: 0"
                                placeholder="最大值"
                                v-model="form.maximumValue"
                            />
                        </a-form-item>
                    </a-col>
                    <a-col span="12">
                        <a-form-item label="检验人">
                            <a-col span="20">
                                <a-input disabled v-model="form.inspectorName" />
                            </a-col>
                            <a-col span="4">
                                <a-button
                                    type="primary"
                                    block
                                    icon="search"
                                    @click="onSearch('employee')"
                                />
                            </a-col>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
            <!-- 模态框 -->
            <project-query-modal ref="projectQueryModalRef" />
            <employee-query-modal ref="employeeQueryModalRef" />
        </a-modal>
    </div>
</template>

<script>
import Bus from "../../../../utils/Bus";
import dict from "../../../dict.json";
import ProjectQueryModal from "../../../../commons/query/ProjectQueryModal";
import EmployeeQueryModal from "../../../../commons/query/EmployeeQueryModal";

export default {
    components: { ProjectQueryModal, EmployeeQueryModal },
    data() {
        return {
            modalShow: false,
            codeDisabled: false,
            modalTitle: "",
            labelCol: { span: 7 },
            wrapperCol: { span: 16 },
            dict,
            form: {},
        };
    },
    methods: {
        openModal(data) {
            this.form = !!data ? data : {};
            this.modalTitle = !data ? "新增检验任务" : "编辑检验任务";
            this.codeDisabled = !!data;
            this.modalShow = true;
        },
        // 确定按钮操作
        onSubmit() {
            Bus.$emit("standard", this.form);
            this.modalShow = false;
        },
        // 搜索
        onSearch(type) {
            // debugger
            this.$refs[type + "QueryModalRef"].openModal();
        },
    },
    mounted() {
        let self = this;
        Bus.$on("project", function (item) {
            // debugger;
            self.form = item;
            // self.$forceUpdate();
        });
        Bus.$on("employee", function (item) {
            // debugger;
            self.form.inspector = item.id;
            self.form.inspectorName = item.personName;
            self.$forceUpdate();
        });
    },
};
</script>
